package com.fare.taluo.conf;

import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 本地加载.properties文件抽象
 * 在应用使用时，可重写load,或reload方法加载各自的配置文件
 * @author xiangsf 2012-8-29
 *
 */
public abstract class PropertiesConfigLocalLoader implements ConfigLocalLoader {

	protected static Logger logger = Logger.getLogger(PropertiesConfigLocalLoader.class);
	
	protected boolean hasLoad = false;
	
	protected Properties prop = null;

	public PropertiesConfigLocalLoader(){}
	
	public Properties getProp() {
		return prop;
	}

	public void setProp(Properties prop) {
		this.prop = prop;
	}
	
	public boolean isHasLoad() {
		return hasLoad;
	}

	public void setHasLoad(boolean hasLoad) {
		this.hasLoad = hasLoad;
	}
	
	public void load(){
		prop = null;
		try {
			prop = new Properties();
			prop.load(PropertiesConfigLocalLoader.class.getClassLoader().getResourceAsStream(this.getFileName()));
		} catch (IOException e) {
			e.printStackTrace();
			logger.error(String.format("加载配件文件[%s]出错!", this.getFileName()), e);
		}
		if(prop != null) ConfigContainer.getInstance().registerCache(this.getFileName(), prop);
		
		this.setHasLoad(true);
	}
	
}
